const { app, BrowserWindow } = require("electron");
const path  = require("path");

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    },
  })
  win.loadFile("index.html");
}

app.whenReady().then(() => {
  createWindow();

  //如果没有窗口打开 则打开一个窗口 macos
  app.on("activate", function () {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

//关闭所有窗口时 退出应用 适用于linux和windows
app.on("window-all-closed", function () {
  if (process.platform !== "darwin") app.quit();
});
